#include "scene.h"



bool Scene::load(const char* filenameDescriptor)
{
	FILE* data_fd;
	errno_t err;
	int numZeros;
	char extension[10];		
	int initialFrame;
	int finalFrame;	
	int currentFrame;

	if (( err = fopen_s(&data_fd, filenameDescriptor, "r+")) != 0) 
	{
		printf("\nCan't read configuration file.\n");
		return false;
	}

	fscanf_s(data_fd, "%s\n",_nameRootText,511);
	fscanf_s(data_fd, "%d\n",&initialFrame);
	fscanf_s(data_fd, "%d\n",&finalFrame);
	fscanf_s(data_fd, "%d\n",&numZeros);
	fscanf_s(data_fd, "%s\n",extension,9);	

	fclose(data_fd);	

	currentFrame  = initialFrame;

	if(_imageDataSource != NULL)
		delete _imageDataSource;

	_imageDataSource = new CameraDriveImagSeq(_nameRootText,initialFrame,finalFrame,numZeros,extension);

	return true;
}

bool Scene::updateCurrentImage()
{
	_imageCurrentRaw =_imageDataSource->getFrame(false);
	if (_imageCurrentRaw == NULL)
	{
		return false;
	}
	_imageCurrentRGB = _imageDataSource->getFrameRGB(); 
	return true;
}